#ifndef _PRODUCER_H
#define _PRODUCER_H

#include "01_Thread.hpp"
#include "02_TaskQueue.hpp"
#include <time.h>
#include <unistd.h>     // unix standard
#include <stdlib.h>
#include <stdio.h>

//class TaskQueue;

class Producer
:public Thread
{
public:
    Producer(TaskQueue& taskque)
        :_taskque(taskque){}
    ~Producer() = default;

    static void init(TaskQueue& _taskque)
    {
        for(int i = 0; i < _taskque.get_list_init_size(); ++i)
        {
            int num = rand() % 1000;
            _taskque.push(num);
            printf("Producer - Initialize | input num = %d \n", num);
        }

    }

    void run () override
    {
        srand(time(nullptr));
        //不行，这么搞会每个进程都创建8个商品
        //for(int i = 0; i < _taskque.get_list_init_size(); ++i)
        //{
        //    int num = rand() % 1000;
        //    _taskque.push(num);
        //    printf("Producer - Initialize | input num = %d \n", num);
        //}

        while(1){
            sleep(3);
            int num = rand() % 1000;
            _taskque.push(num);
            printf("Producer - Run | input num = %d \n", num);
        }
        
    }
private:
    TaskQueue& _taskque;
};

#endif

